package it.unibo.refolding.pico.ui;

import it.unibo.refolding.pico.PicoShapes;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.shorts.ShortList;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Path2D;
import java.util.List;

import com.google.common.base.Preconditions;

public class ZDefDrawer {

  final DataHolder h;
	private final List<Path2D.Float> paths;
	/**
	 * colors[0] is used for the peak-in-progress
	 */
  private final List<Color> colors;
	
	public ZDefDrawer(DataHolder h, double defScale, List<Color> colors) {
		this.h = h;
		IntList jp = h.junctionPoints();
		ShortList z = h.sharedZ();
		ShortList def = h.sharedDef();
		this.paths = PicoShapes.createPaths(z, def, jp, defScale, h.minZ(), h.minDef());
		Preconditions.checkArgument(colors.size() == h.junctionPoints().size() + 1);
		this.colors = colors;
	}

  void paintComponent(Graphics2D g2) {
		Color savedColor = g2.getColor();
		for (int i = 0; i < paths.size(); ++i) {
		  Path2D.Float path = paths.get(i);
		  g2.setColor(colors.get(i % colors.size()));
		  g2.draw(path);
		}
		g2.setColor(savedColor);
	}
}
